/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
var searchInsert = function(nums, target) {
    var left = 0;
    var right = nums.length;
    var result = nums.length;
    if (nums.length <= 0) {
    	return 0
    }
    if (target < nums[left]) {
    	return 0
    }
    while(left < right) {
    	var mid = parseInt((left + right) / 2)
		let min = nums[mid - 1] || 0;
		let max = nums[mid] || 0;
		if (max > target && min < target) {
			result = mid;
    		left = mid;
    		right = mid;
		} else if (nums[mid] > target) {
			right = mid;
		} else if (nums[mid] < target) {
    		left++;
		} else {
			result = mid;
    		left = mid
    		right = mid;
		}
    }
    return result
};

(function () {
	let nums = [1,3,5,6];
	// nums = [1];
	let target = 7;
	console.log(searchInsert(nums, target))
})()